function result = getrid(A,c,option)
% function result = getrid(A,c,option)
% choose c : 1 for rows or 2 for columns
% Option 1 : Remove rows or cols whose elements are ALL NaN
% Option 2 : Remove rows or cols where ANY element is an NaN

if option == 1
    if c == 1;
        row_loc = find(isnan(nanmean(A,2)) == 1);
        A(row_loc,:) = []; % for nan - rows
        result = A;
    elseif c == 2
        col_loc = find(isnan(nanmean(A,1)) == 1);
        A(:,col_loc) = []; % for nan - columns
        result = A; 
    else
        error('must choose rows or columns')
    end
elseif option == 2
    if c == 1;
        A(any(isnan(A),2),:)=[]; % for nan - rows
        result = A; 
    elseif c == 2
        A(any(isnan(A),1),:)=[]; % for nan - columns
        result = A; 
    else
        error('must choose rows or columns')
    end
end

% 
% 
% function data_out = remove_nan (data_in, remove_dim)
% %remove row or col from the data_in if there is a NaN element
% 
% % e.g., data_in =[1 2 3 4 NaN; 1 2 3 4 5; 1 2 3 NaN NaN]
% % from this data remove col 4 and 5 such that data_out=[ 1 2 3; 1 2 3; 1 2
% % 3]
% 
% if nargin==1
% 
%     col_loc=any(isnan(data_in),1);
%     data_in(:,col_loc)=[];
%     data_out=data_in;
% 
% elseif nargin==2
% 
%     if remove_dim=='col'
%         %find the cols with nan and remove the colums
%         col_loc=any(isnan(data_in),1);
%         data_in(:,col_loc)=[];
%         data_out=data_in;
%     elseif  remove_dim='row'
%         %find the rows with nan and remove the rows
%         row_loc=any(isnan(data_in),2);
%         data_in(row_loc,:)=[];
%         data_out=data_in;
%     end
% else
%     error( 'incorrect no of arguments')
% 
% end